home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
asmutil
/
alib10.zip
/
EDREC.ASM
< prev
next >
Wrap
Assembly Source File
|
1994-04-07
|
32KB
|
1,309 lines
;***************************** EDREC.ASM **********************************
PAGE 70,132
COMMENT
EDREC (Edit Records)
Version 1.0
--------------------
Purpose
-------
EDREC is both a sample program and ALIB utility program. Files
created by EDREC use ALIB database format which is also used by
hyper message and error displays. This greatly simplifies the
process of creating a file of error messages or help screens.
Using EDREC
-----------
EDREC can be started by typing EDREC or by typing EDREC followed
with a file name. If the file exists, EDREC will display the first
record and wait for input. If the file does not exist the record
window will be blank.
The data entered using EDREC is probably going to be displayed in
a window someday, so the window size should be selected to make
data entry easier. The record window size is set by the "Config"
menu option.
After setting the window size, select "Edit" to add or modify
records.
Database Format
---------------
EDREC creates records in a window which can be configured to any size.
Each record is variable length and terminated by a null (hex 00 char).
Compiling
---------
The MASM & LINK commands needed to build EDREC.EXE are:
masm edrec;
link edrec,edrec,,alib.lib;
include mac.inc
include common.inc
;-----------------------------------------------------------------------------
extrn library_setup:far
extrn lib_error_handler:far
extrn error_handler:far
extrn clear_screen:far
extrn display_string:far
extrn display_string_fill:far
extrn put_crt_blk:far
extrn repeat_put_crt:far
extrn BREAK_KEY_INTERCEPT:far
extrn change_path:far
extrn MENU_SYSTEM:far
extrn change_setup:far
extrn restore_path:far
extrn find_home_path:far
extrn library_terminate:far
extrn BREAK_KEY_RESTORE:far
extrn parse_first:far
extrn expand_filename:far
extrn get_string:far
extrn qget_string:far
extrn DEC_STR_TO_WORD:far
extrn WORD_TO_DEC_CRT:far
extrn get_setup:far
extrn save_window:far
extrn restore_window:far
extrn draw_box:far
extrn box_shrink:far
extrn window_string:far
extrn yes_or_no:far
extrn flush_keyboard:far
extrn set_lib_colors:far
extrn dbase_init:far
extrn DBASE_READ:far
extrn dbase_read_next:far
extrn dbase_read_prev:far
extrn dbase_append:far
extrn dbase_replace:far
extrn dbase_insert:far
extrn DBASE_REMOVE:far
extrn dbase_close:far
extrn window_edit:far
extrn window_cstring:far
extrn strlen3:far
extrn qwarn:far
extrn to_upper:far
extrn message:far
;------------------------------------------------------------------------------
code segment para public 'CODE'
assume cs:code, ds:code
;-----------------------------------------------------------------------------
;
edit1_msg db ' Current Record #',0
edit3_msg db '(alt-H) for help ',0
append_msg db 'append',0
insert_msg db 'insert',0
modify_msg db 'modify',0
exit_msg db 'EDREC exiting, do you wish to save the changes in memory? (Y/n)',0
pspseg dw 0
lib_info_ptr dw 0
lib_info_seg dw 0
current_operation db 0 ;0=none 1=append 2=insert 3=replace
current_record dw 1
current_record_ptr dw 0
current_Record_len dw 0
null_file_flag db 0 ;0=file empty
file_asciiz db 40 dup (0)
box_size label word
box_cols db 50 ;columns
box_rows db 5 ;rows
box_location label word
db 14 ;column
db 5 ;row
dirty_flag db 0 ;1=changes have been made
saved_flag db 0 ;1=file has been saved
buffer_size equ 1000 ;largest record size
buffer db buffer_size dup (0)
buffer_ptr dw buffer
cursor_position dw 0
file_create_flag db 0 ;1=create is needed
string1 db 3 dup (0)
string2 db 3 dup (0)
help_asciiz db 'EDREC.HLP',0
null_file_msg db 'The database does not contain any records'
db ' select the EDIT and APPEND options to add'
db ' records, or CONFIG option to change setup.'
db 0dh,0ah,0dh,0ah,'Press any key to continue',0
not_yet_msg db 'This feature not implemented at present. '
db ' Press any key to continue',0
;-----------------------------------------------------------------------------
start:
cli
mov cs:pspseg,es ;save PSP segment
mov ax,cs ;get CODE segment
mov ss,ax
mov ds,ax
mov es,ax
mov sp,offset stack_
sti
; next, release memory beyond the end of the program
; The definition for ZSEG marks the
; end of the program's code, data and stack area.
; When linking be sure ZSEG is at the end of the program.
mov ax,zseg
mov bx,cs:pspseg ;
mov es,bx
sub bx,ax
neg bx ; size of program in paragraphs
mov ah,4Ah ; resize memory block
int 21h
mov ax,cs
mov es,ax
;
; check if enough memory free to run program
;
mov ax,pspseg ;pass psp segment to setup
mov bx,0 ;number of floating point variables
call library_setup
mov lib_info_ptr,si ;save ptr to library info block
mov lib_info_seg,es ; see COMMON.INC or LIBRARY_SETUP
cmp ax,128
jae got_enough_mem ;jmp if 128k of memory avail
mov al,7
mov ah,fatal_return
call lib_error_handler
jmp exitx
got_enough_mem:
;
; clear the screen and display signon
;
mov ah,app_text_color
mov al,' '
call clear_screen
;
; display copyright message
;
mov si,offset copyright_msg
mov ah,app_text_color
mov dx,1008h ;display row 16 column xx
call display_string
; prevent an unintended program crash; trap Ctrl+Break, Ctrl+C and
; Ctrl+Alt+Del key combinations
; call BREAK_KEY_INTERCEPT
;
; switch to home directory
;
push es
call find_home_path
mov bx,di
call change_path
pop es
jnc path_changed
mov al,6
mov ah,fatal_return
call lib_error_handler
jmp exit2
path_changed:
call read_setup
call establish_defaults ;set colors & see if config file avail
call ck_for_filename
;
; read the file (initialize the database)
;
init_database:
mov dx,offset file_asciiz
call dbase_init
mov es,bx ;move selector to es:
;
; if file does not exist, then ask if create ok
;
cmp al,1 ;check if file opened ok
jbe clear_and_display
jmp exit ;jmp if error opening file
;
; clear the screen and display the box
;
clear_and_display:
mov ah,_msg_text_color
mov al,' '
call clear_screen
mov dx,box_location
mov bx,box_size
mov ah,_msg_text_color
mov al,0 ;single line frame
call draw_box
;
; fill box with record info.
;
mov dx,current_record
call DBASE_READ
cmp al,0
je show_rec ;jmp if record found
cmp dx,1 ;check if this is record 1
jne show_rec ;jmp if database has records
;
; current database is empty
;
null_file:
apush ds,es
mov ax,cs
mov ds,ax
mov es,ax
mov ah,cs:_msg_text_color
mov al,0
mov bx,0840h
mov dx,0808h
mov cx,1
mov si,offset null_file_msg
mov bp,msg_save_win+msg_restore_win+msg_anykey+msg_disp+msg_ram
call message
apop es,ds
jmp menu1 ;jmp if empty database
;
; this record is not present in the data base, ask for instructions
;
;
; fill the box with current record contents
; es:si point at data for display
; cx = record length
;
show_rec:
mov null_file_flag,1 ;specify database has data
call move_to_buffer
;
; setup to display buffer
;
display_buffer:
mov bx,box_size
mov dx,box_location
call box_shrink
mov ah,_msg_text_color
mov si,offset buffer
push di
mov di,0
call window_cstring
pop di
;
; display status line with record#
;
call show_rec_status
;
; show menu bar and wait for selection
;
menu1: mov bx,offset menu1_def
mov ah,08h+20h ;restore bar & return unknown keys
call MENU_SYSTEM
cmp cl,1 ;check if process key
jne menu1_d2 ;jmp if not process hit
jmp ax
jmp menu1 ;go do it again
menu1_d2:
cmp cl,4 ;check if abort key
je quit_j
cmp cl,2
jne menu1 ;jmp if unknown mouse or no key press
cmp al,51h
je pgdn_j
cmp al,49h
je pgup_j
jmp menu1
quit_j: jmp quit
p